using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;

namespace Metro.Utils
{
    public class ExpirationHelper : IDisposable
    {
        private const int times = 1000;
        private Timer tmrExpiration;
        private Metro.Admin.BusinessEntities.Transaction transaction=null;  

        public delegate void DelegateExpirationTimer(Metro.Admin.BusinessEntities.Transaction transaction, ExpirationHelper source);
        public event DelegateExpirationTimer ExpirationTimerElapsed;

        public Timer TmrExpiration
        {
            set { this.tmrExpiration = value;}
            get { return this.tmrExpiration; }
        }

        public Metro.Admin.BusinessEntities.Transaction Transaction
        {
            set { this.transaction = value; }
            get { return this.transaction; }
        }


        public ExpirationHelper(Metro.Admin.BusinessEntities.Transaction transaction)
		{
			try
			{
                this.transaction = transaction;
                this.tmrExpiration = new Timer(times);
                this.tmrExpiration.Elapsed += new ElapsedEventHandler(tmrExpiration_Elapsed);
			}
			catch(Exception ex)
			{
				throw ex;
			}
		}

        private void tmrExpiration_Elapsed(object sender, ElapsedEventArgs e)
        {
            this.ExpirationTimerElapsed(this.transaction, this);
        }

        #region IDisposable Members

        public void Dispose()
        {
            if (tmrExpiration != null)
            {
                this.tmrExpiration.Stop();
                this.tmrExpiration.Dispose();
            }
        }

        #endregion
    }
}
